package com.uzai.console.web.vph;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.exception.BusinessException;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenIdDto;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenInfoDto;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenQuery;
import com.uzai.console.dto.vph.vphtoken.VphTokenDto;
import com.uzai.console.dto.vph.vphtoken.VphTokenIdDto;
import com.uzai.console.dto.vph.vphtoken.VphTokenQuery;
import com.uzai.console.dto.vph.vphtoken.VphTokenSetPhDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.locallive.TlbTokenService;
import com.uzai.console.service.vph.VphTokenService;
import com.uzai.console.vo.locallive.tlbtoken.TlbTokenInfoVo;
import com.uzai.console.vo.vph.vphtoken.VphTokenAuthUrlVo;
import com.uzai.console.vo.vph.vphtoken.VphTokenInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 产品
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "唯品会",tags = "唯品会|唯品会联盟")
@ApiSort(12)
@RestController
public class VphTokenController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(VphTokenController.class);

    @Autowired
    private VphTokenService vphTokenService;
    @Autowired
    private TlbTokenService tlbTokenService;

    @ApiOperation(value = "分页查询唯品会联盟列表", notes = "分页查询唯品会联盟列表", response = VphTokenInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/vphToken/findVphTokenList")
    public Object findVphTokenList(@RequestBody VphTokenQuery vphTokenQuery){
        return vphTokenService.findVphTokenList(vphTokenQuery);
    }


    @SystemLogType(model = SystemModelEnum.VphToken, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加联盟账号", notes = "添加联盟账号", response = VphTokenAuthUrlVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/vphToken/addToken")
    public Object addToken(){
        return vphTokenService.addVphToken(getLoginInfo().getMerId());
    }

    @SystemLogType(model = SystemModelEnum.VphToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "重新授权", notes = "重新授权", response = VphTokenAuthUrlVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/vphToken/reauthorize")
    public Object reauthorize(){
        return vphTokenService.addVphToken(getLoginInfo().getMerId());
    }

    @ApiOperation(value = "查询联盟详情", notes = "查询联盟详情", response = VphTokenInfoVo.class)
    @ApiOperationSupport(order = 4)
    @PostMapping("/vphToken/findVphTokenInfo")
    public Object findVphTokenInfo(@RequestBody VphTokenIdDto vphTokenIdDto){
        return vphTokenService.findVphTokenInfo(vphTokenIdDto);
    }

    @ApiOperation(value = "更新联盟信息", notes = "更新联盟信息")
    @ApiOperationSupport(order = 5)
    @PostMapping("/vphToken/updateVphToken")
    public Object updateVphToken(@RequestBody VphTokenDto vphTokenDto){
        if (Objects.isNull(vphTokenDto) || Objects.isNull(vphTokenDto.getId())) {
            throw new BusinessException("更新参数错误");
        }
        return vphTokenService.updateVphToken(vphTokenDto);
    }

    @SystemLogType(model = SystemModelEnum.VphToken, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除", notes = "删除")
    @ApiOperationSupport(order = 6)
    @PostMapping("/vphToken/deleteVphToken")
    public Object deleteVphToken(@RequestBody VphTokenIdDto vphTokenIdDto){
        vphTokenService.deleteVphToken(vphTokenIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.VphToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "启用炮灰", notes = "启用炮灰")
    @ApiOperationSupport(order = 7)
    @PostMapping("/vphToken/setPh")
    public Object setPh(@RequestBody VphTokenSetPhDto vphTokenSetPhDto){
        vphTokenService.setPh(vphTokenSetPhDto);
        return true;
    }

    @ApiOperation(value = "分页查询推老板唯品会联盟列表", notes = "分页查询推老板唯品会联盟列表", response = TlbTokenInfoVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/vphToken/findTlbTokenList")
    public Object findTlbTokenList(@RequestBody TlbTokenQuery tlbTokenQuery){
        if(StringUtils.isBlank(tlbTokenQuery.getType())){
            tlbTokenQuery.setType("vph");
        }
        return tlbTokenService.findTlbTokenList(tlbTokenQuery);
    }

    @ApiOperation(value = "查询推老板唯品会联盟详情", notes = "查询推老板唯品会联盟详情", response = TlbTokenInfoVo.class)
    @PostMapping("/vphToken/findTlbTokenInfo")
    public Object findTlbToken(@RequestBody TlbTokenIdDto tlbTokenIdDto){
        return tlbTokenService.findTlbTokenInfo(tlbTokenIdDto);
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加推老板唯品会联盟账号", notes = "添加推老板唯品会联盟账号")
    @ApiOperationSupport(order = 8)
    @PostMapping("/vphToken/addTlbToken")
    public Object addTlbToken(@RequestBody TlbTokenInfoDto tlbTokenInfoDto){
        if(StringUtils.isBlank(tlbTokenInfoDto.getType())){
            tlbTokenInfoDto.setType("vph");
        }
        tlbTokenService.addTlbToken(tlbTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改推老板唯品会联盟账号", notes = "修改推老板唯品会联盟账号")
    @ApiOperationSupport(order = 9)
    @PostMapping("/vphToken/updateTlbToken")
    public Object updateTlbToken(@RequestBody TlbTokenInfoDto tlbTokenInfoDto){
        tlbTokenService.updateTlbToken(tlbTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除推老板唯品会联盟账户", notes = "删除推老板唯品会联盟账户")
    @ApiOperationSupport(order = 10)
    @PostMapping("/vphToken/deleteTlbToken")
    public Object deleteTlbToken(@RequestBody TlbTokenIdDto tlbTokenIdDto){
        if(StringUtils.isBlank(tlbTokenIdDto.getType())){
            tlbTokenIdDto.setType("vph");
        }
        tlbTokenService.deleteTlbToken(tlbTokenIdDto);
        return true;
    }

    @ApiOperation(value = "查询所有共享推老板唯品会联盟列表", notes = "查询所有共享推老板唯品会联盟列表", response = TlbTokenInfoVo.class)
    @ApiOperationSupport(order = 12)
    @PostMapping("/vphToken/findTlbVphTokenListSelect")
    public Object findTlbVphTokenListSelect(@RequestBody TlbTokenQuery tlbTokenQuery){
        if(StringUtils.isBlank(tlbTokenQuery.getType())){
            tlbTokenQuery.setType("vph");
        }
        return tlbTokenService.findTlbTokenListSelect(tlbTokenQuery);
    }

}
